package com.lineage.server.serverpackets;

import com.lineage.server.datatables.PetItemTable;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PetInstance;
import java.util.Iterator;
import java.util.List;

public class S_PetInventory extends ServerBasePacket {
  private byte[] _byte;
  
  public S_PetInventory(L1PetInstance pet, boolean b) {
    this._byte = null;
    isTrue(pet);
  }
  
  private void isTrue(L1PetInstance pet) {
    List<L1ItemInstance> itemList = pet.getInventory().getItems();
    writeC(176);
    writeD(pet.getId());
    writeH(itemList.size());
    writeC(11);
    int petAc = 10;
    Iterator<L1ItemInstance> iterator = itemList.iterator();
    while (iterator.hasNext()) {
      L1ItemInstance item = iterator.next();
      if (item != null) {
        writeD(item.getId());
        writeC(22);
        writeH(item.get_gfxid());
        writeC(item.getBless());
        writeD((int)Math.min(item.getCount(), 2000000000L));
        if (item.getItem().getType2() == 0 && item.getItem().getType() == 11 && item.isEquipped()) {
          writeC(item.isIdentified() ? 3 : 2);
          petAc += PetItemTable.get().getTemplate(item.getItemId()).getAddAc();
        } else {
          writeC(item.isIdentified() ? 1 : 0);
        } 
        writeS(item.getViewName());
      } 
    } 
    writeC(petAc);
  }
  
  public byte[] getContent() {
    if (this._byte == null)
      this._byte = getBytes(); 
    return this._byte;
  }
  
  public String getType() {
    return getClass().getSimpleName();
  }
}
